package Day21;

import java.util.ArrayList;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        int T = in.nextInt();
        ArrayList<int[]> list = new ArrayList<>();

        for (int i = 0; i < T; i++) {
            int n = in.nextInt();
            int tmpN = n;
            int k = in.nextInt();
            int[] ints1 = new int[n];
            int[] ints2 = new int[n];

            for (int j = 0; j < n; j++) {
                ints1[j] = in.nextInt();
            }
            for (int j = 0; j < n; j++) {
                ints2[j] = in.nextInt();
            }

            int[] ret = new int[2 * n];
            for (int l = 0; l < k; l++) {
                tmpN = n;
                //洗牌
                for (int j = 2 * n; j > 0; j-=2, tmpN--) {
                    ret[j - 1] = ints2[tmpN - 1];
                    ret[j - 2] = ints1[tmpN - 1];
                }
                //更新ints1和ints2的值
                if (l != k) {
                    for (int j = 0; j < n; j++) {
                        ints1[j] = ret[j];
                    }
                    for (int j = 0; j < n; j++) {
                        ints2[j] = ret[j + n];
                    }
                }
            }

            list.add(ret);
        }

        for (int i = 0; i < T; i++) {
            int[] sout = list.get(i);
            for (int j = 0; j < sout.length - 1; j++) {
                System.out.print(sout[j] + " ");
            }
            System.out.println(sout[sout.length - 1]);
        }

    }

    public static void main0(String[] args) {

        Scanner in = new Scanner(System.in);
        int n = Integer.parseInt(in.nextLine());
        char[] ops = (in.nextLine()).toCharArray();

        int cur = 1;

        if (n <= 4) {

            int front = 1;
            int tail = n;
            for (char op : ops) {
                if (op == 'U') {
                    if (cur == front) {
                        cur = tail;
                    } else {
                        cur--;
                    }
                } else if (op == 'D') {
                    if (cur == tail) {
                        cur = front;
                    } else {
                        cur++;
                    }
                } else {
                    System.out.println("指令输入出错");
                    return;
                }
            }

            //打印当前页面
            for (int i = 1; i < n; i++) {
                System.out.print(i + " ");
            }
            System.out.println(n);
            //打印光标
            System.out.println(cur);

        } else {
            cur = 1;

            //menu initialization
            int[] menu = new int[n];
            for (int i = 0; i < n; i++) {
                menu[i] = i + 1;
            }

            //页面初始化
            int front = 1;
            int tail = n;
            int mFront = front;
            int mTail = 4;

            for (char op: ops) {
                if (op == 'U') {
                    if (cur == mFront && mFront == front) {
                        mFront = menu[n - 4];
                        mTail = menu[n - 1];
                        cur = tail;
                    } else if (cur == mFront) {
                        mFront--;
                        mTail--;
                        cur = mFront;
                    } else {
                        cur--;
                    }
                } else if (op == 'D') {
                    if (cur == mTail && mTail == tail) {
                        mFront = menu[0];
                        mTail = menu[3];
                        cur = front;
                    } else if (cur == mTail) {
                        mTail++;
                        mFront++;
                        cur = mTail;
                    } else {
                        cur++;
                    }
                }
            }

            //打印当前页面
            for (int i = 0; i < 3; i++) {
                System.out.print((mFront + i) + " ");
            }
            System.out.println(mTail);
            //打印光标
            System.out.println(cur);
        }
    }

}
